home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / tstcom.lqr / TSTCOM.LBR / tstcom.c next >
Text File  |  2011-02-04  |  4KB  |  121 lines

  1. /*
  2.  * tstcom.c  27 Oct 83  Craig Milo Rogers at USC/ISI
  3.  *
  4.  *    This program tests the COM1: communications package
  5.  * by using it to convert the IBM PC into a simple "glass
  6.  * TTY".  The simulation is enhanced if you are running the
  7.  * ANSI terminal driver.  For production use this program
  8.  * would have to be modified so DOS doesn't trap control-C,
  9.  * etc.
  10.  */
  11.  
  12. #define M_TSTCOM
  13.  
  14. #include "stdio.h"
  15.  
  16. #include "truth.h"
  17. #include "beauty.h"
  18.  
  19. #define TNESCAPE 0036        /* "Telnet" escape char:  control-uparrow. */
  20.  
  21. #define RBUFLEN 4096        /* Receive buffer length. */
  22. #define TBUFLEN 512        /* Transmit buffer length. */
  23. static char rbuf1[RBUFLEN];    /* Receive data buffer. */
  24. static char tbuf1[TBUFLEN];    /* Transmit data buffer. */
  25. static char rbuf2[RBUFLEN];    /* Receive data buffer. */
  26. static char tbuf2[TBUFLEN];    /* Transmit data buffer. */
  27.  
  28. main(argc,argv)
  29. int argc;            /* Number of arguments. */
  30. char *argv[];            /* Pointers to argument strings. */
  31. {
  32.     int divisor = 12;        /* Baud rage generator divisor for
  33.                  * 9600 baud. */
  34.     int c;            /* Holds a data character. */
  35.     bool sawesc;        /* Indicates that ctrl-q was last char. */
  36.     bool running;        /* FALSE indicates exit request. */
  37.     int i;            /* Counter. */
  38.     int unit;            /* COM: unit number. */
  39.  
  40.     int_ini();            /* Initialize the interrupt package. */
  41.  
  42.                 /* Initialize COM1: and COM2:. */
  43.     com_ini(1, divisor, tbuf1, TBUFLEN, rbuf1, RBUFLEN);
  44.     com_ini(2, divisor, tbuf2, TBUFLEN, rbuf2, RBUFLEN);
  45.  
  46.     sawesc = FALSE;        /* Start off with normal data. */
  47.     running = TRUE;        /* Running the glass tty. */
  48.     unit = 1;            /* Start on COM1:. */
  49.  
  50.     while (running) {        /* Until we decide to exit: */
  51.     if (kbhit() != 0) {    /* Got a character? */
  52.         c = getch();    /* Pick up the character. */
  53.         if (sawesc) {    /* Did we just see telnet escape? */
  54.         sawesc = FALSE;    /* Cancel the saw-escape flag. */
  55.         switch (c &0177) {    /* Dispatch to command processor. */
  56.  
  57.         case TNESCAPE:    /* A second escape char. */
  58.             com_putc(unit, c);    /* Pass it through. */
  59.             break;
  60.  
  61.         case 'b':    /* A request to send BREAK. */
  62.         case 'B':
  63.             com_break(unit);
  64.             break;
  65.  
  66.         case 'c':    /* The "close" command. */
  67.         case 'C':
  68.         case 'e':    /* The "exit" command. */
  69.         case 'E':
  70.         case 'q':    /* The "quit" command. */
  71.         case 'Q':
  72.             running = FALSE;
  73.             continue;
  74.  
  75.         case '1':    /* Switch to COM1:. */
  76.             unit = 1;
  77.             break;
  78.  
  79.         case '2':    /* Switch to COM2:. */
  80.             unit = 2;
  81.             break;
  82.  
  83.         default:    /* Complain about bad char. */
  84.             putch(0007);    /* Ring the "bell". */
  85.             break;
  86.         }
  87.         } else {        /* Otherwise, didn't see escape prev. */
  88.         switch (c &0177) {    /* Dispatch to character processor. */
  89.  
  90.         case TNESCAPE:        /* Process "Telnet" escape char. */
  91.             sawesc = TRUE;    /* Set saw-escape flag. */
  92.             break;
  93.  
  94.         case 0010:            /* Convert backspace */
  95.             com_putc(unit, 0177);    /*   into <DEL>. */
  96.             break;
  97.  
  98.         case 0177:            /* Convert <DEL> */
  99.             com_putc(unit, 0010);    /*   into backspace. */
  100.             break;
  101.  
  102.         default:        /* Otherwise, send to COM: as is. */
  103.             com_putc(unit, c);    /* Ignore errors. */
  104.         }
  105.         }
  106.     }
  107.     for (i = com_icnt(unit); i > 0; i--) {
  108.         c = com_getc(unit);    /* Drain some COM1: characters. */
  109.  
  110.         if ((c != 0) && (c != 0177)) {
  111.                     /* Ignore padding chars. */
  112.         putch(c);        /* Display on screen. */
  113.         }
  114.     }
  115.     }
  116.  
  117.     com_trm(1);            /* Restore interrupt vectors, etc. */
  118.     com_trm(2);
  119.     int_trm();
  120. }
  121.